(function(){function e(e){this.editor=e;this.specialParsers={};this.DEFAULT_NODE_NAME="span",this.WHITE_SPACE_REG_EXP=/\s+/,this.defaultRules={tags:{},classes:{}};this.convertedBxNodes=[];this.rules={};if(!this.editor.util.FirstLetterSupported()){this.firstNodeCheck=false;this.FIRST_LETTER_CLASS="bxe-first-letter";this.FIRST_LETTER_CLASS_CHROME="bxe-first-letter-chrome";this.FIRST_LETTER_SPAN="bxe-first-letter-s"}}e.prototype={Parse:function(e,t,r,i,s){if(!r){r=document}this.convertedBxNodes=[];this.firstNodeCheck=false;var a=r.createDocumentFragment(),n=this.GetAsDomElement(e,r),o,l,d;this.SetParseBxMode(s);this.pasteNodeIndexTmp=BX.clone(this.editor.pasteNodeIndex);while(n.firstChild){d=n.firstChild;n.removeChild(d);o=this.Convert(d,i,s,o);if(o){l=!s&&this.CheckBlockNode(o);if(BX.browser.IsFirefox()&&o.nodeName=="DIV"){l=false}a.appendChild(o);if(l){a.appendChild(this.editor.util.GetInvisibleTextNode())}}}n.innerHTML="";n.appendChild(a);e=this.RegexpContentParse(this.editor.GetInnerHtml(n),s);return e},SetParseBxMode:function(e){this.bParseBx=!!e},CodeParse:function(e){return e},GetAsDomElement:function(e,t){if(!t)t=document;var r=t.createElement("DIV");if(typeof e==="object"&&e.nodeType){r.appendChild(e)}else if(this.editor.util.CheckHTML5Support()){r.innerHTML=e}else if(this.editor.util.CheckHTML5FullSupport()){r.style.display="none";t.body.appendChild(r);try{r.innerHTML=e}catch(e){}t.body.removeChild(r)}return r},Convert:function(e,t,r,i){var s=false,a=e.nodeType,n=e.childNodes,o,l,d,u;if(a==1){if(e.nodeName=="IMG"){if(!e.getAttribute("data-bx-orig-src"))e.setAttribute("data-bx-orig-src",e.getAttribute("src"));else e.setAttribute("src",e.getAttribute("data-bx-orig-src"))}if(this.editor.pasteHandleMode&&(r||this.editor.bbParseContentMode)){if(e.id=="bx-cursor-node"){return e.ownerDocument.createTextNode(this.editor.INVISIBLE_CURSOR)}var f=e.getAttribute("data-bx-paste-flag");s=f!=="Y"&&!this.pasteNodeIndexTmp[f];if(e&&e.id){u=this.editor.GetBxTag(e.id);if(u.tag){s=false}}if(s){e=this.CleanNodeAfterPaste(e,i);if(!e){return null}n=e.childNodes;a=e.nodeType}e.removeAttribute("data-bx-paste-flag");if(this.pasteNodeIndexTmp[f])delete this.pasteNodeIndexTmp[f]}else{if(e.id=="bx-cursor-node"){return e.cloneNode(true)}}if(a==1){if(!e.__bxparsed){if(this.IsAnchor(e)&&!e.getAttribute("data-bx-replace_with_children")){o=e.cloneNode(true);o.innerHTML="";l=null;for(d=0;d<n.length;d++){l=this.Convert(n[d],t,r,l);if(l){o.appendChild(l)}}var h={};for(d=0;d<o.attributes.length;d++){if(o.attributes[d].name!=="name")h[o.attributes[d].name]=o.attributes[d].value}e=this.editor.phpParser.GetSurrogateNode("anchor",BX.message("BXEdAnchor")+": #"+o.name,null,{html:o.innerHTML,name:o.name,attributes:h})}else if(this.IsPrintBreak(e)){e=this.GetPrintBreakSurrogate(e)}if(e&&e.id){u=this.editor.GetBxTag(e.id);if(u.tag){e.__bxparsed=1;if(this.bParseBx){o=e.ownerDocument.createTextNode("~"+u.id+"~");this.convertedBxNodes.push(u)}else{o=e.cloneNode(true)}return o}}if(!o&&e.nodeType){o=this.ConvertElement(e,r)}}}}else if(a==3){o=this.HandleText(e)}if(!o){return null}for(d=0;d<n.length;d++){l=this.Convert(n[d],t,r);if(l){o.appendChild(l)}}if(o.nodeType==1){if(o.style&&BX.util.trim(o.style.cssText)==""&&o.removeAttribute){o.removeAttribute("style")}if(this.editor.config.cleanEmptySpans&&t&&o.childNodes.length<=1&&o.nodeName.toLowerCase()===this.DEFAULT_NODE_NAME&&!o.attributes.length){return o.firstChild}}return o},ConvertElement:function(e,t){var r,i,s,a,n,o=this.editor.GetParseRules().tags,l=e.nodeName.toLowerCase(),d=e.scopeName;if(e.__bxparsed){return null}e.__bxparsed=1;if(e.className==="bx-editor-temp"){return null}if(d&&d!="HTML"){l=d+":"+l}if("outerHTML"in e&&!this.editor.util.AutoCloseTagSupported()&&e.nodeName==="P"&&e.outerHTML.slice(-4).toLowerCase()!=="</p>"){l="div"}if(!this.editor.util.FirstLetterSupported()&&e.className){if(e.className==this.FIRST_LETTER_CLASS&&!this.bParseBx){this.HandleFirstLetterNode(e)}else if(e.className==this.FIRST_LETTER_CLASS_CHROME&&this.bParseBx){this.HandleFirstLetterNodeBack(e)}}if(l=="table"&&!this.bParseBx){var u=parseInt(e.getAttribute("border"),10);if(!u){e.removeAttribute("border");e.setAttribute("data-bx-no-border","Y")}}if(l in o){r=o[l];if(!r||r.remove){return null}if(r.clean_empty&&(e.innerHTML===""||e.innerHTML===this.editor.INVISIBLE_SPACE)&&(!e.className||e.className=="")&&(!this.editor.lastCreatedId||this.editor.lastCreatedId!=e.getAttribute("data-bx-last-created-id"))){return null}r=typeof r==="string"?{rename_tag:r}:r;n=e.getAttribute("data-bx-new-rule");if(n){r[n]=e.getAttribute("data-bx-"+n)}}else if(e.firstChild){r={rename_tag:this.DEFAULT_NODE_NAME}}else{return null}if(r.convert_attributes&&t==false){for(i in r.convert_attributes){if(r.convert_attributes.hasOwnProperty(i)&&e.getAttribute(i)){s=this.ConvertAttributeValueToCss(i,r.convert_attributes[i],e.getAttribute(i));if(s!==false){r.replace_with_children=false;e.style[r.convert_attributes[i]]=s}e.removeAttribute(i)}}}if(r.replace_with_children){a=e.ownerDocument.createDocumentFragment()}else{a=e.ownerDocument.createElement(r.rename_tag||l);this.HandleAttributes(e,a,r,t)}if(n){r[n]=null;delete r[n]}if((!a.className||a.className=="")&&a.removeAttribute){a.removeAttribute("class")}e=null;return a},CleanNodeAfterPaste:function(e,t){var r,i,s=e.nodeName,a=e.innerHTML,n=BX.util.trim(a),o={align:1,alt:1,bgcolor:1,border:1,cellpadding:1,cellspacing:1,color:1,colspan:1,height:1,href:1,rowspan:1,size:1,span:1,src:1,style:1,target:1,title:1,type:1,value:1,width:1},l={B:1,STRONG:1,I:1,EM:1,U:1,DEL:1,S:1,STRIKE:1},d={A:1,SPAN:1,B:1,STRONG:1,I:1,EM:1,U:1,DEL:1,S:1,STRIKE:1,H1:1,H2:1,H3:1,H4:1,H5:1,H6:1,ABBR:1,TIME:1,FIGURE:1,FIGCAPTION:1};if(s=="IFRAME"){return null}if(e.style.display=="none"||e.style.visibility=="hidden"){return null}if(d[s]&&a==""){return null}var u=e.getAttribute("data-bx-clean-attribute");if(u){e.removeAttribute(u);e.removeAttribute("data-bx-clean-attribute")}if(s=="IMG"){var f=e.getAttribute("alt");if(f===""){e.removeAttribute("alt")}else if(typeof f=="string"&&f!==""&&f.indexOf("://")!==-1){this.CheckAltImage(e)}e.removeAttribute("class");this.CleanNodeCss(e);return e}if(s=="A"&&(n==""||n=="&nbsp;")){return null}if(s==="A"){BX.onCustomEvent(this.editor,"OnAfterLinkInserted",[e.getAttribute("href")])}e.removeAttribute("class");e.removeAttribute("id");i=0;while(i<e.attributes.length){r=e.attributes[i].name;if(!o[r]||e.attributes[i].value==""){e.removeAttribute(r)}else{i++}}if(s=="THEAD"){var h=e.getElementsByTagName("TR"),c;for(i=0;i<h.length;i++){if(h[i]&&h[i].getAttribute){c=h[i].getAttribute("style");if(c&&c.indexOf("mso-yfti-irow")!==-1&&c.indexOf("mso-yfti-irow:0")===-1&&c.indexOf("mso-yfti-irow:-1")===-1&&c.indexOf("mso-yfti-firstrow:yes")===-1){e.setAttribute("data-bx-new-rule","rename_tag");e.setAttribute("data-bx-rename_tag","TBODY");break}}}}if(s=="DIV"||e.style.display=="block"||s=="FORM"){if(!e.lastChild||e.lastChild&&e.lastChild.nodeName!="BR"){e.appendChild(e.ownerDocument.createElement("BR")).setAttribute("data-bx-paste-flag","Y")}if(t&&typeof t=="object"&&t.nodeType==3&&e.firstChild){e.insertBefore(e.ownerDocument.createElement("BR"),e.firstChild).setAttribute("data-bx-paste-flag","Y")}e.setAttribute("data-bx-new-rule","replace_with_children");e.setAttribute("data-bx-replace_with_children","1")}if(s=="B"&&e.style.fontWeight=="normal"){e.setAttribute("data-bx-new-rule","replace_with_children");e.setAttribute("data-bx-replace_with_children","1")}if(l[s]&&this.editor.config.pasteSetDecor){e.setAttribute("data-bx-new-rule","replace_with_children");e.setAttribute("data-bx-replace_with_children","1")}if(l[s]&&this.editor.config.pasteSetDecor){e.setAttribute("data-bx-new-rule","replace_with_children");e.setAttribute("data-bx-replace_with_children","1")}if(this.IsAnchor(e)&&(e.name==""||BX.util.trim(e.name==""))){e.setAttribute("data-bx-new-rule","replace_with_children");e.setAttribute("data-bx-replace_with_children","1")}if(BX.util.in_array(s,this.editor.TABLE_TAGS)&&this.editor.config.pasteClearTableDimen){e.removeAttribute("width");e.removeAttribute("height")}this.CleanNodeCss(e);if(s=="SPAN"&&e.style.cssText==""){e.setAttribute("data-bx-new-rule","replace_with_children");e.setAttribute("data-bx-replace_with_children","1")}if((s=="P"||s=="SPAN"||s=="FONT")&&BX.util.trim(e.innerHTML)=="&nbsp;"){e.innerHTML=" "}return e},CleanNodeCss:function(e){var t,r,i,s,a,n=e.nodeName,o={width:["auto"],height:["auto"]};if(BX.util.in_array(n,this.editor.TABLE_TAGS)&&this.editor.config.pasteClearTableDimen){o={}}if(!this.editor.config.pasteSetColors){o["color"]=["#000000","#000","black"];o["background-color"]=["transparent","#fff","#ffffff","white"];o["background"]=1}if(!this.editor.config.pasteSetBorders){o["border-collapse"]=1;o["border-color"]=["transparent","#fff","#ffffff","white"];o["border-style"]=["none","hidden"];o["border-top"]=["0px","0"];o["border-right"]=["0px","0"];o["border-bottom"]=["0px","0"];o["border-left"]=["0px","0"];o["border-top-color"]=["transparent","#fff","#ffffff","white"];o["border-right-color"]=["transparent","#fff","#ffffff","white"];o["border-bottom-color"]=["transparent","#fff","#ffffff","white"];o["border-left-color"]=["transparent","#fff","#ffffff","white"];o["border-top-style"]=["none","hidden"];o["border-right-style"]=["none","hidden"];o["border-bottom-style"]=["none","hidden"];o["border-left-style"]=["none","hidden"];o["border-top-width"]=["0px","0"];o["border-right-width"]=["0px","0"];o["border-bottom-width"]=["0px","0"];o["border-left-width"]=["0px","0"];o["border-width"]=["0px","0"];o["border"]=["0px","0"]}if(!this.editor.config.pasteSetDecor){o["font-style"]=["normal"];o["font-weight"]=["normal"];o["text-decoration"]=["none"]}if(e.style&&BX.util.trim(e.style.cssText)!=""&&n!=="BR"){t=[];for(a in e.style){if(e.style.hasOwnProperty(a)){if(parseInt(a).toString()===a){i=e.style[a];s=e.style.getPropertyValue(i)}else{i=a;s=e.style.getPropertyValue(i)}if(s===null)continue;if(!o[i]||s.match(/^-(moz|webkit|ms|o)/gi)||s=="inherit"||s=="initial"||i=="color"&&n=="A"||(n=="SPAN"||n=="P")&&(i=="width"||i=="height")||typeof o[i]=="object"&&BX.util.in_array(s.toLowerCase(),o[i])){continue}if(i.indexOf("color")!==-1){s=this.editor.util.RgbToHex(s);if(typeof o[i]=="object"&&BX.util.in_array(s.toLowerCase(),o[i])||s=="transparent"){continue}}if(i.indexOf("border")!==-1&&s.indexOf("none")!==-1){continue}t.push({name:i,value:s})}}e.removeAttribute("style");if(t.length>0){for(r=0;r<t.length;r++){e.style[t[r].name]=t[r].value}}}else{e.removeAttribute("style")}},CheckAltImage:function(e){var t=this.editor.GetIframeDoc();function r(e){var r,i=t.getElementsByTagName("IMG");for(r=0;r<i.length;r++){if(i[r].src===e){return i[r]}}}function i(){if(e.src===e.alt&&e.getAttribute("data-bx-orig-src")!==e.src){e.setAttribute("data-bx-orig-src",e.getAttribute("src"))}BX.unbind(e,"load",i);BX.unbind(e,"error",s)}function s(){var t=e.getAttribute("alt"),a=r(e.src);if(!a){BX.unbind(e,"load",i);BX.unbind(e,"error",s);return}if(e.getAttribute("src")!==e.alt){a.setAttribute("src",t)}else{a.setAttribute("src",e.getAttribute("data-bx-orig-src"));BX.unbind(e,"load",i);BX.unbind(e,"error",s)}}BX.bind(e,"load",i);BX.bind(e,"error",s)},HandleText:function(e){var t=e.data;if(this.editor.pasteHandleMode&&t.indexOf("EndFragment:")!==-1){t=t.replace(/Version:\d\.\d(?:\s|\S)*?StartHTML:\d+(?:\s|\S)*?EndHTML:\d+(?:\s|\S)*?StartFragment:\d+(?:\s|\S)*?EndFragment:\d+(?:\s|\n|\t|\r)*/g,"")}return e.ownerDocument.createTextNode(t)},HandleAttributes:function(e,t,r,i){var s={},a=r.set_class,n=r.add_class,o=r.add_css,l=r.set_attributes,d=r.check_attributes,u=r.clear_attributes,f=this.editor.GetParseRules().classes,h=0,c,p={},g,m=[],b=[],T=[],B=[],S,v,P,x,C,A,y,I;if(d){for(A in d){I=this.GetCheckAttributeHandler(d[A]);if(!I)continue;y=I(this.GetAttributeEx(e,A));if(typeof y==="string"&&y!=="")s[A]=y}}var E=e.getAttribute("data-bx-clean-attribute");if(E){e.removeAttribute(E);e.removeAttribute("data-bx-clean-attribute")}if(!u){for(h=0;h<e.attributes.length;h++){C=e.attributes[h];if(i){if(C.name.substr(0,15)=="data-bx-app-ex-"){c=C.name.substr(15);s[c]=e.getAttribute(C.name);p[c]=true}if(p[C.name]){continue}}if(C.name.substr(0,8)=="data-bx-"&&C.name!="data-bx-noindex"&&this.bParseBx){continue}s[C.name]=this.GetAttributeEx(e,C.name)}}if(a)m.push(a);if(o){for(g in o){if(o.hasOwnProperty(g))t.style[g]=o[g]}}B=e.getAttribute("class");if(B)m=m.concat(B.split(this.WHITE_SPACE_REG_EXP));S=m.length;for(;h<S;h++){P=m[h];if(f[P])b.push(P)}if(T.length)s["class"]=T.join(" ");for(A in s){try{t.setAttribute(A,s[A])}catch(e){}}if(s.src){if(typeof s.width!=="undefined")t.setAttribute("width",s.width);if(typeof s.height!=="undefined")t.setAttribute("height",s.height)}},ConvertAttributeValueToCss:function(e,t,r){if(e=="size"&&t=="fontSize"){var i={1:"9px",2:"13px",3:"16px",4:"18px",5:"24px",6:"32px",7:"48px"};if(i[r]){r=i[r]}else if(r<1){r=false}else if(r>7){r=i[7]}}return r},GetAttributeEx:function(e,t){t=t.toLowerCase();var r,i=e.nodeName;if(i=="IMG"&&t=="src"&&this.IsLoadedImage(e)===true){r=e.getAttribute("src")}else if(!this.editor.util.CheckGetAttributeTruth()&&"outerHTML"in e){var s=e.outerHTML.toLowerCase(),a=s.indexOf(" "+t+"=")!=-1;r=a?e.getAttribute(t):null}else{r=e.getAttribute(t)}return r},IsLoadedImage:function(e){try{return e.complete&&!e.mozMatchesSelector(":-moz-broken")}catch(t){if(e.complete&&e.readyState==="complete")return true}return false},GetCheckAttributeHandler:function(e){var t=this.GetCheckAttributeHandlers();return t[e]},GetCheckAttributeHandlers:function(){return{url:function(e){return e},alt:function(e){if(!e){return""}return e.replace(/[^ a-z0-9_\-]/gi,"")},numbers:function(e){e=(e||"").replace(/\D/g,"");return e||null}}},HandleBitrixNode:function(e){return e},RegexpContentParse:function(e,t){if(e.indexOf("rgb")!==-1){e=e.replace(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+))?\)/gi,(function(e,t,r,i,s){function a(e){return("0"+parseInt(e).toString(16)).slice(-2)}return"#"+a(t)+a(r)+a(i)}))}if(t&&e.indexOf("data-bx-noindex")!==-1){e=e.replace(/(<a[^<]*?)data\-bx\-noindex="Y"([\s\S]*?>[\s\S]*?\/a>)/gi,(function(e,t,r){return"\x3c!--noindex--\x3e"+t+r+"\x3c!--/noindex--\x3e"}))}if(t){e=e.replace(/\uFEFF/gi,"")}else{e=e.replace(/\uFEFF+/gi,this.editor.INVISIBLE_SPACE)}if(t&&e.indexOf("#BXAPP")!==-1){var r=this;e=e.replace(/#BXAPP(\d+)#/g,(function(e,t){t=parseInt(t,10);return r.editor.phpParser.AdvancedPhpGetFragmentByIndex(t,true)}))}return e},IsAnchor:function(e){return e.nodeName=="A"&&!e.href},IsPrintBreak:function(e){return e.style.pageBreakAfter=="always"},GetPrintBreakSurrogate:function(e){var t=this.editor.GetIframeDoc(),r=this.editor.SetBxTag(false,{tag:"printbreak",params:{innerHTML:BX.util.trim(e.innerHTML)},name:BX.message("BXEdPrintBreakName"),title:BX.message("BXEdPrintBreakTitle")});return BX.create("IMG",{props:{src:this.editor.EMPTY_IMAGE_SRC,id:r,className:"bxhtmled-printbreak",title:BX.message("BXEdPrintBreakTitle")}},t)},CheckBlockNode:function(e){return this.editor.phpParser.IsSurrogate(e)||e.nodeType==1&&(e.style.display=="block"||e.style.display=="inline-block"||e.nodeName=="BLOCKQUOTE"||e.nodeName=="DIV")},HandleFirstLetterNode:function(e){this.firstNodeCheck=true;e.className=this.FIRST_LETTER_CLASS_CHROME;var t=true,r=this.editor.GetIframeDoc(),i,s,a=this._GetFlTextNode(e),n=this._GetFlSpan(e);if(a){i=BX.util.trim(this.editor.util.GetTextContent(a));if(n){this._FLCleanNodesBeforeFirstSpan(n);s=BX.util.trim(this.editor.util.GetTextContent(n));if(i.substr(0,1)==s&&s.length==1){t=false}else if(i==s&&s.length>1){t=false;this.editor.SetCursorNode();this.editor.util.InsertAfter(r.createTextNode(i.substr(1)),n);this.editor.RestoreCursor();n.innerHTML=i.substr(0,1)}this._FLCleanNodesBeforeFirstSpan(n)}if(t){if(n){this.editor.SetCursorNode();this.editor.util.ReplaceWithOwnChildren(n);this.editor.RestoreCursor()}n=BX.create("SPAN",{props:{className:this.FIRST_LETTER_SPAN},text:i.substr(0,1)},e.ownerDocument);this.editor.util.SetTextContent(a,i.substr(1));a.parentNode.insertBefore(n,a);this._FLCleanNodesBeforeFirstSpan(n)}this._FLCleanBogusSpans(e)}},HandleFirstLetterNodeBack:function(e){this.firstNodeCheck=true;e.className=this.FIRST_LETTER_CLASS;var t=this._GetFlSpan(e);if(t){this.editor.util.ReplaceWithOwnChildren(t)}},_GetFlSpan:function(e){return BX.findChild(e,{className:this.FIRST_LETTER_SPAN},1)},_GetFlTextNode:function(e){if(e.innerHTML==""||!e.firstChild)return null;if(e.firstChild&&e.firstChild.nodeType==3&&e.firstChild.nodeValue&&BX.util.trim(e.firstChild.nodeValue)!=="")return e.firstChild;var t=0,r=this,i=e;while(t++<=100){i=BX.findChild(i,(function(e){return BX.util.trim(r.editor.util.GetTextContent(e))!==""}),false);if(i.nodeType==3&&i.nodeValue&&BX.util.trim(i.nodeValue)!==""){return i}}return null},FirstLetterCheckNodes:function(e,t,r){var i=this.editor.GetIframeDoc(),s;if(this.firstNodeCheck||e.indexOf(this.FIRST_LETTER_CLASS)!==-1||r===true){var a,n=i.querySelectorAll("."+this.FIRST_LETTER_CLASS),o=i.querySelectorAll("."+this.FIRST_LETTER_CLASS_CHROME);for(s=0;s<o.length;s++){a=BX.util.trim(o[s].innerHTML);if(a==""||a=="<br>"){BX.remove(o[s]);continue}this.HandleFirstLetterNode(o[s])}for(s=0;s<n.length;s++){this.HandleFirstLetterNode(n[s])}this.firstNodeCheck=!!(n.length||o.length)}if(!this.firstNodeCheck&&e.indexOf(this.FIRST_LETTER_SPAN)!==-1){var l=i.querySelectorAll("."+this.FIRST_LETTER_SPAN);for(s=0;s<l.length;s++){this.editor.util.ReplaceWithOwnChildren(l[s])}}},_FLCleanNodesBeforeFirstSpan:function(e){while(e.previousSibling){BX.remove(e.previousSibling)}},_FLCleanBogusSpans:function(e){var t,r=e.getElementsByTagName("SPAN");for(t=r.length-1;t>=0;t--){if(!r[t].className&&r[t].style.lineHeight&&r[t].style.fontSize)this.editor.util.ReplaceWithOwnChildren(r[t])}},FirstLetterBackspaceHandler:function(e){if(e.collapsed&&e.startOffset==0){var t=e.startContainer.previousSibling;if(t&&t.className.indexOf(this.FIRST_LETTER_SPAN)!==-1){this.editor.selection.SetAfter(t.lastChild)}}}};function t(e){this.PHP_PATTERN="#BXPHP_IND#";this.editor=e;this.allowed={php:this.editor.allowPhp||this.editor.lpa,javascript:true,style:true,htmlcomment:true,iframe:true,video:true,audio:true,object:true};this.bUseAPP=true;this.APPConfig={arTags_before:["tbody","thead","tfoot","tr","td","th"],arTags_after:["tbody","thead","tfoot","tr","td","th"],arTags:{a:["href","title","class","style"],img:["src","alt","class","style","width","height"],input:["id","name","value"]}};this.customParsers=[];this.arScripts={};this.arJavascripts={};this.arHtmlComments={};this.arIframes={};this.arVideos={};this.arAudio={};this.arStyles={};this.arObjects={};this.surrClass="bxhtmled-surrogate";this.surrogateTags={component:1,php:1,javascript:1,style:1,htmlcomment:1,anchor:1,iframe:1,video:1,audio:1,object:1};BX.addCustomEvent(this.editor,"OnIframeMouseDown",BX.proxy(this.OnSurrogateMousedown,this));BX.addCustomEvent(this.editor,"OnIframeDblClick",BX.proxy(this.OnSurrogateDblClick,this));BX.addCustomEvent(this.editor,"OnIframeKeydown",BX.proxy(this.OnSurrogateKeydown,this));BX.addCustomEvent(this.editor,"OnAfterCommandExec",BX.proxy(this.RenewSurrogates,this))}t.prototype={ParsePhp:function(e){var t=this;if(this.IsAllowed("php")){e=this.ReplacePhpBySymCode(e)}else{e=this.CleanPhp(e)}e=this.CustomContentParse(e);e=this.ReplaceJavascriptBySymCode(e);e=this.ReplaceHtmlCommentsBySymCode(e);e=this.ReplaceIframeBySymCode(e);e=this.ReplaceAudioBySymCode(e);e=this.ReplaceStyleBySymCode(e);e=this.ReplaceObjectBySymCode(e);e=this.ParseBreak(e);e=this.AdvancedPhpParse(e);e=this.ParseSymCode(e);if(this.editor.lpa){e=e.replace(/#PHP(\d+)#/g,(function(e){return t.GetSurrogateHTML("php_protected",BX.message("BXEdPhpCode")+" *",BX.message("BXEdPhpCodeProtected"),{value:e})}));e=e.replace(/#BXAPP(\d+)#/g,(function(e,r){r=parseInt(r);return t.editor.phpParser.AdvancedPhpGetFragmentByIndex(r,false)}))}return e},ReplacePhpBySymCode:function(e,t){var r=[],i=0,s,a,n,o,l,d,u,f=0;t=t===true;while((i=e.indexOf("<?",i))>=0){f=0;s=i+1;a=false;n=false;while(s<e.length-1){s++;o=e.substr(s,1);if(!n){if(o=="/"&&s+1<e.length){l=e.indexOf("?>",s);if(l==-1){i=e.length;break}l+=2;d=0;if(e.substr(s+1,1)=="*"&&(d=e.indexOf("*/",s+2))>=0){d+=2}else if(e.substr(s+1,1)=="/"&&(d=e.indexOf("\n",s+2))>=0){d+=1}if(d>0){if(d>l&&e.substr(s+1,1)!="*"){r.push([i,l,e.substr(i,l-i)]);i=l;break}else{s=d-1}}continue}if(o=="?"&&s+1<e.length&&e.substr(s+1,1)==">"){s=s+2;r.push([i,s,e.substr(i,s-i)]);i=s+1;break}}if(n&&o=="\\"){a=true;continue}if(o=='"'||o=="'"){if(n){if(!a&&u==o)n=false}else{n=true;u=o}}a=false}if(s>=e.length)break;i=s}this.arScripts={};if(r.length>0){var h="",c=0,p;if(t){for(s=0;s<r.length;s++){p=r[s];h+=e.substr(c,p[0]-c);c=p[1]}}else{for(s=0;s<r.length;s++){p=r[s];h+=e.substr(c,p[0]-c)+this.SavePhpCode(p[2],s);c=p[1]}}e=h+e.substr(c)}return e},CleanPhp:function(e){return this.ReplacePhpBySymCode(e,true)},ReplaceJavascriptBySymCode:function(e){this.arJavascripts={};var t=this,r=0;e=e.replace(/<script[\s\S]*?\/script>/gi,(function(e){t.arJavascripts[r]=e;var i=t.GetPattern(r,false,"javascript");r++;return i}));return e},ReplaceHtmlCommentsBySymCode:function(e){this.arHtmlComments={};var t=this,r=0;e=e.replace(/(<!--noindex-->)(?:[\s|\n|\r|\t]*?)<a([\s\S]*?)\/a>(?:[\s|\n|\r|\t]*?)(<!--\/noindex-->)/gi,(function(e,t,r,i){return'<a data-bx-noindex="Y"'+r+"/a>"}));e=e.replace(/<!--[\s\S]*?-->/gi,(function(e){t.arHtmlComments[r]=e;return t.GetPattern(r++,false,"html_comment")}));return e},ReplaceIframeBySymCode:function(e){this.arIframes={};var t=this,r=0;e=e.replace(/<iframe([\s\S]*?)\/iframe>/gi,(function(e,i){var s=t.CheckForVideo(i);if(s){t.arVideos[r]={html:e,provider:s.provider||false,src:s.src||false};return t.GetPattern(r++,false,"video")}else{t.arIframes[r]=e;return t.GetPattern(r++,false,"iframe")}}));return e},ReplaceStyleBySymCode:function(e){this.arStyles={};var t=this,r=0;e=e.replace(/<style[\s\S]*?\/style>/gi,(function(e){t.arStyles[r]=e;return t.GetPattern(r++,false,"style")}));return e},ReplaceAudioBySymCode:function(e){this.arAudio={};var t=this,r=0;e=e.replace(/<audio[\s\S]*?\/audio>/gi,(function(e){t.arAudio[r]=e;return t.GetPattern(r++,false,"audio")}));return e},ReplaceObjectBySymCode:function(e){this.arObjects={};var t=this,r=0;e=e.replace(/<object[\s\S]*?\/object>/gi,(function(e){t.arObjects[r]=e;return t.GetPattern(r++,false,"object")}));e=e.replace(/<embed[\s\S]*?(?:\/embed)?>/gi,(function(e){t.arObjects[r]=e;return t.GetPattern(r++,false,"object")}));return e},CheckForVideo:function(e){var t=new RegExp("(?:src)\\s*=\\s*(\"|')([\\s\\S]*?((?:youtube.com)|(?:youtu.be)|(?:rutube.ru)|(?:vimeo.com)|(?:vk.com)|(?:"+location.host+"))[\\s\\S]*?)(\\1)","ig");var r=t.exec(e);if(r){return{src:r[2],provider:this.GetVideoProviderName(r[3],e)}}else{return false}},GetVideoProviderName:function(e,t){var r="";if(!BX.type.isNotEmptyString(t)){t=""}switch(e){case"youtube.com":case"youtu.be":r="YouTube";break;case"rutube.ru":r="Rutube";break;case"vimeo.com":r="Vimeo";break;case"vk.com":r="Vk";break;case location.host:var i=/((?:provider))=([\S]+)(?:&*)/gi;res=i.exec(t);if(res){r=res[2]}break}return r},SavePhpCode:function(e,t){this.arScripts[t]=e;return this.GetPhpPattern(t,false)},GetPhpPattern:function(e,t){if(t)return new RegExp("#BXPHP_"+e+"#","ig");else return"#BXPHP_"+e+"#"},GetPattern:function(e,t,r){var i;switch(r){case"php":i="#BXPHP_";break;case"javascript":i="#BXJAVASCRIPT_";break;case"html_comment":i="#BXHTMLCOMMENT_";break;case"iframe":i="#BXIFRAME_";break;case"style":i="#BXSTYLE_";break;case"video":i="#BXVIDEO_";break;case"audio":i="#BXAUDIO_";break;case"object":i="#BXOBJECT_";break;default:return""}return t?new RegExp(i+e+"#","ig"):i+e+"#"},ParseSymCode:function(e){var t=this;e=e.replace(/#BX(PHP|JAVASCRIPT|HTMLCOMMENT|IFRAME|STYLE|VIDEO|AUDIO|OBJECT)_(\d+)#/g,(function(e,r,i){var s="";if(t.IsAllowed(r.toLowerCase())){switch(r){case"PHP":s=t.GetPhpCodeHTML(t.arScripts[i]);break;case"JAVASCRIPT":s=t.GetJavascriptCodeHTML(t.arJavascripts[i]);break;case"HTMLCOMMENT":s=t.GetHtmlCommentHTML(t.arHtmlComments[i]);break;case"IFRAME":s=t.GetIframeHTML(t.arIframes[i]);break;case"STYLE":s=t.GetStyleHTML(t.arStyles[i]);break;case"VIDEO":s=t.GetVideoHTML(t.arVideos[i]);break;case"AUDIO":s=t.GetAudioHTML(t.arAudio[i]);break;case"OBJECT":s=t.GetObjectHTML(t.arObjects[i]);break}}return s||e}));return e},GetPhpCodeHTML:function(e){if(typeof e!=="string")return null;var t="",r=this.editor.components.IsComponent(e);if(r!==false){var i=this.editor.components.GetComponentData(r.name),s=i.title||r.name,a=i.params&&i.params.DESCRIPTION?i.params.DESCRIPTION:a;if(i.className){r.className=i.className||""}t=this.GetSurrogateHTML("component",s,a,r)}else{if(this.editor.allowPhp){t=this.GetSurrogateHTML("php",BX.message("BXEdPhpCode"),BX.message("BXEdPhpCode")+": "+this.GetShortTitle(e,200),{value:e})}else{t=""}}return t},GetJavascriptCodeHTML:function(e){if(typeof e!=="string")return null;return this.GetSurrogateHTML("javascript","Javascript","Javascript: "+this.GetShortTitle(e,200),{value:e})},GetHtmlCommentHTML:function(e){if(typeof e!=="string")return null;return this.GetSurrogateHTML("htmlcomment",BX.message("BXEdHtmlComment"),BX.message("BXEdHtmlComment")+": "+this.GetShortTitle(e),{value:e})},GetIframeHTML:function(e){if(typeof e!=="string")return null;return this.GetSurrogateHTML("iframe",BX.message("BXEdIframe"),BX.message("BXEdIframe")+": "+this.GetShortTitle(e),{value:e})},GetStyleHTML:function(e){if(typeof e!=="string")return null;return this.GetSurrogateHTML("style",BX.message("BXEdStyle"),BX.message("BXEdStyle")+": "+this.GetShortTitle(e),{value:e})},GetVideoHTML:function(e){var t="video",r=e.params||this.FetchVideoIframeParams(e.html,e.provider);r.value=e.html;var i=this.editor.SetBxTag(false,{tag:t,name:r.title,params:r}),s=this.editor.SetBxTag(false,{tag:"surrogate_dd",params:{origParams:r,origId:i}});this.editor.SetBxTag({id:i},{tag:t,name:r.title,params:r,title:r.title,surrogateId:s});var a='<span id="'+i+'" title="'+r.title+'"  class="'+this.surrClass+" bxhtmled-video-surrogate"+'" '+'style="min-width:'+r.width+"px; max-width:"+r.width+"px; min-height:"+r.height+"px; max-height:"+r.height+'px"'+">"+'<img title="'+r.title+'" id="'+s+'" class="bxhtmled-surrogate-dd" src="'+this.editor.util.GetEmptyImage()+'"/>'+'<span class="bxhtmled-surrogate-inner"><span class="bxhtmled-video-icon"></span><span class="bxhtmled-comp-lable" spellcheck=false>'+r.title+"</span></span>"+"</span>";return a},GetAudioHTML:function(e){if(typeof e!=="string")return null;var t="Audio",r=this.FetchVideoIframeParams(e);if(r&&r.src){t+=": "+this.GetShortTitle(BX.util.htmlspecialchars(r.src))}return this.GetSurrogateHTML("audio",t,"Audio: "+this.GetShortTitle(e),{value:e})},GetObjectHTML:function(e){return this.GetSurrogateHTML("object",BX.message("BXEdObjectEmbed"),BX.message("BXEdObjectEmbed")+": "+this.GetShortTitle(e),{value:e})},FetchVideoIframeParams:function(e,t){var r=/((?:src)|(?:title)|(?:width)|(?:height))\s*=\s*("|')([\s\S]*?)(\2)/gi,i={src:"",width:180,height:100,title:t?BX.message("BXEdVideoTitleProvider").replace("#PROVIDER_NAME#",t):BX.message("BXEdVideoTitle"),origTitle:""};e.replace(r,(function(e,t,r,s){t=t.toLowerCase();if(t=="width"||t=="height"){s=parseInt(s,10);if(s&&!isNaN(s)){i[t]=s}}else if(t=="title"){i.origTitle=BX.util.htmlspecialcharsback(s);i.title+=": "+s}else{i[t]=s}return e}));return i},GetSurrogateHTML:function(e,t,r,i){if(r){r=BX.util.htmlspecialchars(r);r=r.replace('"','"')}if(!i){i={}}var s=this.editor.SetBxTag(false,{tag:e,name:t,params:i}),a=this.editor.SetBxTag(false,{tag:"surrogate_dd",params:{origParams:i,origId:s}});this.editor.SetBxTag({id:s},{tag:e,name:t,params:i,title:r,surrogateId:a});if(!this.surrogateTags.tag){this.surrogateTags.tag=1}var n='<span id="'+s+'" title="'+(r||t)+'"  class="'+this.surrClass+(i.className?" "+i.className:"")+'">'+this.GetSurrogateInner(a,r,t)+"</span>";return n},GetSurrogateNode:function(e,t,r,i){var s=this.editor.GetIframeDoc(),a=this.editor.SetBxTag(false,{tag:e,name:t,params:i,title:r}),n=this.editor.SetBxTag(false,{tag:"surrogate_dd",params:{origParams:i,origId:a}});if(!i)i={};this.editor.SetBxTag({id:a},{tag:e,name:t,params:i,title:r,surrogateId:n});if(!this.surrogateTags.tag){this.surrogateTags.tag=1}return BX.create("SPAN",{props:{id:a,title:r||t,className:this.surrClass+(i.className?" "+i.className:"")},html:this.GetSurrogateInner(n,r,t)},s)},GetSurrogateInner:function(e,t,r){return'<img title="'+(t||r)+'" id="'+e+'" class="bxhtmled-surrogate-dd" src="'+this.editor.util.GetEmptyImage()+'"/>'+'<span class="bxhtmled-surrogate-inner"><span class="bxhtmled-right-side-item-icon"></span><span class="bxhtmled-comp-lable" unselectable="on" spellcheck=false>'+BX.util.htmlspecialchars(r)+"</span></span>"},GetShortTitle:function(e,t){if(e.length>100)e=e.substr(0,100)+"...";return e},_GetUnParsedContent:function(e){var t=this;e=e.replace(/#BX(PHP|JAVASCRIPT|HTMLCOMMENT|IFRAME|STYLE|VIDEO|AUDIO|OBJECT)_(\d+)#/g,(function(e,r,i){var s;switch(r){case"PHP":s=t.arScripts[i];break;case"JAVASCRIPT":s=t.arJavascripts[i];break;case"HTMLCOMMENT":s=t.arHtmlComments[i];break;case"IFRAME":s=t.arIframes[i];break;case"STYLE":s=t.arStyles[i];break;case"VIDEO":s=t.arVideos[i].html;break;case"AUDIO":s=t.arAudio[i];break;case"OBJECT":s=t.arObjects[i].html;break}return s}));return e},IsSurrogate:function(e){return e&&BX.hasClass(e,this.surrClass)},TrimPhpBrackets:function(e){if(e.substr(0,2)!="<?")return e;if(e.substr(0,5).toLowerCase()=="<?php")e=e.substr(5);else e=e.substr(2);e=e.substr(0,e.length-2);return e},TrimQuotes:function(e,t){var r,i;e=e.trim();if(t==undefined){r=e.substr(0,1);i=e.substr(0,1);if(r=='"'&&i=='"'||r=="'"&&i=="'")e=e.substring(1,e.length-1)}else{if(!t.length)return e;r=e.substr(0,1);i=e.substr(0,1);t=t.substr(0,1);if(r==t&&i==t)e=e.substring(1,e.length-1)}return e},CleanCode:function(e){var t=false,r=false,i="",s=-1,a,n,o;while(s<e.length-1){s++;a=e.substr(s,1);if(!r){if(a=="/"&&s+1<e.length){n=0;if(e.substr(s+1,1)=="*"&&(n=e.indexOf("*/",s+2))>=0)n+=2;else if(e.substr(s+1,1)=="/"&&(n=e.indexOf("\n",s+2))>=0)n+=1;if(n>0){if(s>n)alert("iti="+s+"="+n);s=n}continue}if(a==" "||a=="\r"||a=="\n"||a=="\t")continue}if(r&&a=="\\"){t=true;i+=a;continue}if(a=='"'||a=="'"){if(r){if(!t&&o==a)r=false}else{r=true;o=a}}t=false;i+=a}return i},ParseFunction:function(e){var t=e.indexOf("("),r=e.lastIndexOf(")");if(t>=0&&r>=0&&t<r)return{name:e.substr(0,t),params:e.substring(t+1,r)};return false},ParseParameters:function(e){e=this.CleanCode(e);var t=this.GetParams(e),r,i,s=t.length;for(i=0;i<s;i++){if(t[i].substr(0,6).toLowerCase()=="array("||t[i].substr(0,1).toLowerCase()=="["){t[i]=this.GetArray(t[i])}else{r=this.TrimQuotes(t[i]);if(this.IsNum(r)||t[i]!=r)t[i]=r;else t[i]=this.WrapPhpBrackets(t[i])}}return t},GetArray:function(e){var t=e.substr(0,1).toLowerCase()=="[",r={};if(e.substr(0,6).toLowerCase()!="array("&&!t){return e}e=e.substring(t?1:6,e.length-1);var i=this.GetParams(e),s,a,n,o,l;for(l=0;l<i.length;l++){if(i[l].substr(0,6).toLowerCase()=="array("||i[l].substr(0,1).toLowerCase()=="["){r[l]=this.GetArray(i[l]);continue}n=i[l].indexOf("=>");if(n==-1){if(i[l]==this.TrimQuotes(i[l]))r[l]=this.WrapPhpBrackets(i[l]);else r[l]=this.TrimQuotes(i[l])}else{s=this.TrimQuotes(i[l].substr(0,n));a=i[l].substr(n+2);o=this.TrimQuotes(a);if(a==o){a=this.WrapPhpBrackets(a);if(a.substr(0,6).toLowerCase()=="array("||a.substr(0,1).toLowerCase()=="["){a=this.GetArray(a)}}else{a=this.TrimQuotes(a)}r[s]=a}}return r},WrapPhpBrackets:function(e){e=e.trim();var t=e.substr(0,1),r=e.substr(0,1);if(t=='"'&&r=='"'||t=="'"&&r=="'")return e;return"={"+e+"}"},GetParams:function(e){var t=[],r=0,i=0,s,a,n=1,o=1,l,d="";for(l=0;l<e.length;l++){s=e.substr(l,1);if(s=='"'&&o==1&&!a){n*=-1}else if(s=="'"&&n==1&&!a){o*=-1}else if(s=="\\"&&!a){a=true;d+=s;continue}if(a)a=false;if(o==-1||n==-1){d+=s;continue}if(s=="["){r++}else if(s=="]"){r--}else if(s=="("){i++}else if(s==")"){i--}else if(s==","&&r==0&&i==0){t.push(d);d="";continue}if(i<0||r<0){break}d+=s}if(d!=""){t.push(d)}return t},IsNum:function(e){var t=e;e=parseFloat(t);if(isNaN(e))e=parseInt(t);if(!isNaN(e))return t==e;return false},ParseBxNodes:function(e){var t,r=this.editor.parser.convertedBxNodes,i=r.length;for(t=0;t<i;t++){if(r[t].tag=="surrogate_dd"){e=e.replace("~"+r[t].params.origId+"~","")}}this._skipNodeIndex={};this._skipNodeList=[];var s=this;e=e.replace(/~(bxid\d{1,9})~/gi,(function(e,t){if(!s._skipNodeIndex[t]){var r=s.editor.GetBxTag(t);if(r&&r.tag){var i=s.GetBxNode(r.tag);if(i){return i.Parse(r.params,t)}}}return""}));return e},GetBxNodeList:function(){var e=this;this.arBxNodes={component:{Parse:function(t,r){return e.editor.components.GetSource(t,r)}},component_icon:{Parse:function(t){return e.editor.components.GetOnDropHtml(t)}},surrogate_dd:{Parse:function(t){if(BX.browser.IsFirefox()||!t||!t.origId){return""}var r=e.editor.GetBxTag(t.origId);if(r){e._skipNodeIndex[t.origId]=true;e._skipNodeList.push(t.origId);var i=e.GetBxNode(r.tag);if(i){return i.Parse(r.params)}}return"#parse surrogate_dd#"}},php:{Parse:function(t){return e._GetUnParsedContent(t.value)}},php_protected:{Parse:function(e){return e.value}},javascript:{Parse:function(t){return e._GetUnParsedContent(t.value)}},htmlcomment:{Parse:function(t){return e._GetUnParsedContent(t.value)}},iframe:{Parse:function(t){return e._GetUnParsedContent(t.value)}},style:{Parse:function(t){return e._GetUnParsedContent(t.value)}},video:{Parse:function(t){return e._GetUnParsedContent(t.value)}},audio:{Parse:function(t){return e._GetUnParsedContent(t.value)}},object:{Parse:function(t){return e._GetUnParsedContent(t.value)}},anchor:{Parse:function(e){var t="";if(e.attributes){for(var r in e.attributes){if(e.attributes.hasOwnProperty(r)){t+=r+'="'+e.attributes[r]+'" '}}}return"<a "+t+(e.name?'name="'+e.name+'"':"")+">"+e.html+"</a>"}},pagebreak:{Parse:function(e){return"<BREAK />"}},printbreak:{Parse:function(e){return'<div style="page-break-after: always">'+e.innerHTML+"</div>"}}};this.editor.On("OnGetBxNodeList");return this.arBxNodes},AddBxNode:function(e,t){if(this.arBxNodes==undefined){var r=this;BX.addCustomEvent(this.editor,"OnGetBxNodeList",(function(){r.arBxNodes[e]=t}))}else{this.arBxNodes[e]=t}},GetBxNode:function(e){if(!this.arBxNodes){this.arBxNodes=this.GetBxNodeList()}return this.arBxNodes[e]||null},OnSurrogateMousedown:function(e,t,r){var i=this;if(r.tag=="surrogate_dd"){BX.bind(t,"dragstart",(function(e){i.OnSurrogateDragStart(e,this)}));BX.bind(t,"dragend",(function(e){i.OnSurrogateDragEnd(e,this,r)}))}else{setTimeout((function(){var e=i.CheckParentSurrogate(i.editor.selection.GetSelectedNode());if(e){i.editor.selection.SetAfter(e);if(!e.nextSibling||e.nextSibling.nodeType!=3){var t=i.editor.util.GetInvisibleTextNode();i.editor.selection.InsertNode(t);i.editor.selection.SetAfter(t)}}}),0)}},OnSurrogateDragEnd:function(e,t,r){if(!document.querySelectorAll)return;var i=this.editor.GetIframeDoc(),s,a,n,o={},l=i.querySelectorAll(".bxhtmled-surrogate"),d=i.querySelectorAll(".bxhtmled-surrogate-dd"),u=l.length;for(s=0;s<d.length;s++){if(d[s]&&d[s].id==r.id){BX.remove(d[s])}}for(s=0;s<u;s++){a=l[s];if(o[a.id]){if(a.getAttribute("data-bx-paste-flag")=="Y"||!o[a.id].getAttribute("data-bx-paste-flag"))BX.remove(a);else if(o[a.id].getAttribute("data-bx-paste-flag"))BX.remove(o[a.id])}else{o[a.id]=a;n=this.editor.GetBxTag(a.id);a.innerHTML=this.GetSurrogateInner(n.surrogateId,n.title,n.name)}}},OnSurrogateDragStart:function(e,t){if(BX.browser.IsFirefox()){this.editor.GetIframeDoc().body.appendChild(t)}},CheckParentSurrogate:function(e){if(!e){return false}if(this.IsSurrogate(e)){return e}var t=this,r=0,i=BX.findParent(e,(function(e){return r++>4||t.IsSurrogate(e)}),this.editor.GetIframeDoc().body);return this.IsSurrogate(i)?i:false},CheckSurrogateDd:function(e){return e&&e.nodeType==1&&this.editor.GetBxTag(e).tag=="surrogate_dd"},OnSurrogateClick:function(e,t){var r=this.editor.GetBxTag(t);if(r&&r.tag=="surrogate_dd"){var i=this.editor.GetBxTag(r.params.origId);this.editor.On("OnSurrogateClick",[r,i,t,e])}},OnSurrogateDblClick:function(e,t){var r=this.editor.GetBxTag(t);if(r&&r.tag=="surrogate_dd"){var i=this.editor.GetBxTag(r.params.origId);this.editor.On("OnSurrogateDblClick",[r,i,t,e])}},OnSurrogateKeyup:function(e,t,r,i){var s,a,n=this.editor.selection.GetRange();if(n){if(n.collapsed){}else{}}},OnSurrogateKeydown:function(e,t,r,i){var s,a=this.editor.KEY_CODES,n=this.editor.selection.GetRange(),o,l,d,u=i;if(!n||!n.getNodes)return;if(!n.collapsed){if(t===a["backspace"]||t===a["delete"]){var f,h=n.getNodes([3]);for(f=0;f<h.length;f++){s=this.editor.util.CheckSurrogateNode(h[f]);if(s){l=this.editor.GetBxTag(s);if(this.surrogateTags[l.tag]){this.RemoveSurrogate(s,l)}}}}}if(t===a["delete"]&&n.collapsed){o=this.editor.util.GetInvisibleTextNode();this.editor.selection.InsertNode(o);this.editor.selection.SetAfter(o);var c=o.nextSibling;if(c){if(c&&c.nodeName=="BR"){c=c.nextSibling}if(c&&c.nodeType==3&&(c.nodeValue=="\n"||this.editor.util.IsEmptyNode(c))){c=c.nextSibling}if(c){BX.remove(o);l=this.editor.GetBxTag(c);if(this.surrogateTags[l.tag]){this.RemoveSurrogate(c,l);return BX.PreventDefault(e)}}}}else if(t===a["backspace"]&&n.collapsed){o=this.editor.util.GetInvisibleTextNode();this.editor.selection.InsertNode(o);this.editor.selection.SetAfter(o);var p=this.editor.util.GetPreviousNotEmptySibling(o);if(p&&this.editor.phpParser.IsSurrogate(p)){BX.remove(p);if(o)BX.remove(o);return BX.PreventDefault(e)}else{if(o)BX.remove(o)}}if(n.startContainer&&n.startContainer==n.endContainer&&n.startContainer.nodeName!=="BODY"){u=n.startContainer;d=this.editor.util.CheckSurrogateNode(u);if(d){l=this.editor.GetBxTag(d.id);if(t===a["backspace"]||t===a["delete"]){this.RemoveSurrogate(d,l);BX.PreventDefault(e)}else if(t===a["left"]||t===a["up"]){var g=d.previousSibling;if(g&&g.nodeType==3&&this.editor.util.IsEmptyNode(g))this.editor.selection._MoveCursorBeforeNode(g);else this.editor.selection._MoveCursorBeforeNode(d);return BX.PreventDefault(e)}else if(t===a["right"]||t===a["down"]){var m=d.nextSibling;if(m&&m.nodeType==3&&this.editor.util.IsEmptyNode(m))this.editor.selection._MoveCursorAfterNode(m);else this.editor.selection._MoveCursorAfterNode(d);return BX.PreventDefault(e)}else if(t===a.shift||t===a.ctrl||t===a.alt||t===a.cmd||t===a.cmdRight){return BX.PreventDefault(e)}else{this.editor.selection._MoveCursorAfterNode(d)}}}},RemoveSurrogate:function(e,t){this.editor.undoManager.Transact();BX.remove(e);this.editor.On("OnSurrogateRemove",[e,t])},CheckHiddenSurrogateDrag:function(){var e,t;for(t=0;t<this.hiddenDd.length;t++){e=this.editor.GetIframeElement(this.hiddenDd[t]);if(e){e.style.visibility=""}}this.hiddenDd=[]},GetAllSurrogates:function(e){if(!document.querySelectorAll)return[];e=e===true;var t=this.editor.GetIframeDoc(),r=[],i,s,a,n=t.querySelectorAll(".bxhtmled-surrogate");for(i=0;i<n.length;i++){s=n[i];a=this.editor.GetBxTag(s.id);if(a.tag||e){r.push({node:s,bxTag:a})}}return r},RenewSurrogates:function(){var e=true,t,r={},i,s=this.GetAllSurrogates(true);for(t=0;t<s.length;t++){if(!s[t].bxTag.tag){BX.remove(s[t].node);continue}i=s[t].bxTag.surrogateId;if(!r[i]||!e){r[i]=i;s[t].node.innerHTML=this.GetSurrogateInner(s[t].bxTag.surrogateId,s[t].bxTag.title,s[t].bxTag.name)}else{BX.remove(s[t].node)}}},RedrawSurrogates:function(){var e,t=this.GetAllSurrogates();for(e=0;e<t.length;e++){if(t[e].node){BX.addClass(t[e].node,"bxhtmled-surrogate-tmp")}}setTimeout((function(){for(e=0;e<t.length;e++){if(t[e].node){BX.removeClass(t[e].node,"bxhtmled-surrogate-tmp")}}}),0)},IsAllowed:function(e){return this.allowed[e]},AdvancedPhpParse:function(e){if(this.bUseAPP){this.arAPPFragments=[];e=this.AdvancedPhpParseInAttributes(e)}return e},AdvancedPhpParseBetweenTableTags:function(e){var t=this;function r(e,r,i,s,a){t.arAPPFragments.push(JS_addslashes(r));return i+s+' data-bx-php-before="#BXAPP'+(t.arAPPFragments.length-1)+'#" '+a}function i(e,r,i,s,a){t.arAPPFragments.push(JS_addslashes(a));return r+">"+s+"<"+i+' style="display:none;" data-bx-php-after="#BXAPP'+(t.arAPPFragments.length-1)+'#"></'+i+">"}var s=t.APPConfig.arTags_before,a=t.APPConfig.arTags_after,n,o,d;for(o=0;o<s.length;o++){n=s[o];if(t.limit_php_access)d=new RegExp("#(PHP(?:\\d{4}))#(\\s*)(<"+n+"[^>]*?)(>)","ig");else d=new RegExp("<\\?(.*?)\\?>(\\s*)(<"+n+"[^>]*?)(>)","ig");e=e.replace(d,r)}for(o=0,l=a.length;o<l;o++){n=a[o];if(t.limit_php_access)d=new RegExp("(</("+n+")[^>]*?)>(\\s*)#(PHP(?:\\d{4}))#","ig");else d=new RegExp("(</("+n+")[^>]*?)>(\\s*)<\\?(.*?)\\?>","ig");e=e.replace(d,i)}return e},AdvancedPhpParseInAttributes:function(e){var t=this,r=this.APPConfig.arTags,i,s,a,n;function o(e,r,i,s,a,n,o){var l,d;if(a.match(/#PHP\d+#/g)){t.arAPPFragments.push(a);l=t.arAPPFragments.length-1;d="#BXAPP"+l+"#";return r+i+'="'+d+'"'+n}if(a.indexOf("#BXPHP_")===-1){return e}t.arAPPFragments.push(a);l=t.arAPPFragments.length-1;d=t.AdvancedPhpGetFragmentByIndex(l,true);return r+i+'="'+d+'"'+" data-bx-app-ex-"+i+'="#BXAPP'+l+'#"'+n}for(i in r){if(r.hasOwnProperty(i)){for(a=0;a<r[i].length;a++){s=r[i][a];n=new RegExp("(<"+i+"(?:[^>](?:\\?>)*?)*?)("+s+")\\s*=\\s*((?:\"|')?)([\\s\\S]*?)\\3((?:[^>](?:\\?>)*?)*?>)","ig");e=e.replace(n,o)}}}return e},AdvancedPhpUnParse:function(e){return e},AdvancedPhpGetFragmentByCode:function(e,t){var r=e.substr(6);r=parseInt(r.substr(0,r.length-1),10);return this.AdvancedPhpGetFragmentByIndex(r,t)},AdvancedPhpGetFragmentByIndex:function(e,t){var r=this,i=this.arAPPFragments[e];i=i.replace(/#BXPHP_(\d+)#/g,(function(e,i){var s=r.arScripts[parseInt(i,10)];if(t){var a=r.GetSiteTemplatePath();if(a){s=s.replace(/<\?=\s*SITE_TEMPLATE_PATH;?\s*\?>/i,a);s=s.replace(/<\?\s*echo\s*SITE_TEMPLATE_PATH;?\s*\?>/i,a)}}return s}));return i},ParseBreak:function(e){var t=this;e=e.replace(/<break\s*\/*>/gi,(function(e){return t.GetSurrogateHTML("pagebreak",BX.message("BXEdPageBreakSur"),BX.message("BXEdPageBreakSurTitle"))}));return e},GetSiteTemplatePath:function(){return this.editor.GetTemplateParams().SITE_TEMPLATE_PATH},CustomContentParse:function(e){for(var t=0;t<this.customParsers.length;t++){if(typeof this.customParsers[t]=="function"){e=this.customParsers[t](e)}}return e},AddCustomParser:function(e){if(typeof e=="function")this.customParsers.push(e)}};function r(e){this.editor=e;this.parseAlign=true}r.prototype={Unparse:function(e){var t=this.editor.parser.GetAsDomElement(e,this.editor.GetIframeDoc());t.setAttribute("data-bx-parent-node","Y");e=this.GetNodeHtml(t,true);e=e.replace(/#BR#/gi,"\n");e=e.replace(/&nbsp;/gi," ");e=e.replace(/\uFEFF/gi,"");return e},Parse:function(e){var t=this,r,i;e=e.replace(/</gi,"&lt;");e=e.replace(/>/gi,"&gt;");function s(e){if(!BX.type.isString(e)){return""}return e.replace(/("|<|>|\[|\])/g,"")}var a=[];e=e.replace(/\[code\]((?:\s|\S)*?)\[\/code\]/gi,(function(e,t){a.push('<pre class="bxhtmled-code">'+t+"</pre>");return"#BX_CODE"+(a.length-1)+"#"}));var n,o;for(n in this.editor.parser.specialParsers){if(this.editor.parser.specialParsers.hasOwnProperty(n)){o=this.editor.parser.specialParsers[n];if(o&&o.Parse){e=o.Parse(n,e,this.editor)}}}if(this.editor.sortedSmiles){var l=[],d=[],u;e=e.replace(/\[(?:\s|\S)*?\]/gi,(function(e){d.push(e);return"#BX_TMP_TAG"+(d.length-1)+"#"}));e=e.replace(/(?:https?|ftp):\/\//gi,(function(e){l.push(e);return"#BX_TMP_URL"+(l.length-1)+"#"}));i=this.editor.sortedSmiles.length;var f,h="\\s.,;:!?\\#\\-\\*\\|\\[\\]\\(\\)\\{\\}<>&\\n\\t\\r",c;for(r=0;r<i;r++){u=this.editor.sortedSmiles[r];if(u.path&&u.code){c="";if(u.width)c+="width:"+parseInt(u.width)+"px;";if(u.height)c+="height:"+parseInt(u.height)+"px;";if(c!=="")c='style="'+c+'"';f='<img id="'+t.editor.SetBxTag(false,{tag:"smile",params:u})+'" src="'+u.path+'" title="'+(u.name||u.code)+'" '+c+"/>";e=e.replace(new RegExp("(["+h+"])"+BX.util.preg_quote(u.code)+"(["+h+"])","ig"),"$1"+f+"$2");e=e.replace(new RegExp("(["+h+"])"+BX.util.preg_quote(u.code)+"$","ig"),"$1"+f);e=e.replace(new RegExp("^"+BX.util.preg_quote(u.code)+"(["+h+"])","ig"),f+"$1");e=e.replace(new RegExp("^"+BX.util.preg_quote(u.code)+"$","ig"),f)}}if(l.length>0){e=e.replace(/#BX_TMP_URL(\d+)#/gi,(function(e,t){return l[t]||e}))}if(d.length>0){e=e.replace(/#BX_TMP_TAG(\d+)#/gi,(function(e,t){return d[t]||e}))}}e=e.replace(/\[quote\]/gi,'<blockquote class="bxhtmled-quote">');e=e.replace(/\[\/quote\]\n?/gi,"</blockquote>");e=e.replace(/[\r\n\s\t]?\[table\][\r\n\s\t]*?\[tr\]/gi,'<table border="1">[TR]');e=e.replace(/\[tr\][\r\n\s\t]*?\[td\]/gi,"[TR][TD]");e=e.replace(/\[tr\][\r\n\s\t]*?\[th\]/gi,"[TR][TH]");e=e.replace(/\[\/td\][\r\n\s\t]*?\[td\]/gi,"[/TD][TD]");e=e.replace(/\[\/tr\][\r\n\s\t]*?\[tr\]/gi,"[/TR][TR]");e=e.replace(/\[\/td\][\r\n\s\t]*?\[\/tr\]/gi,"[/TD][/TR]");e=e.replace(/\[\/th\][\r\n\s\t]*?\[\/tr\]/gi,"[/TH][/TR]");e=e.replace(/\[\/tr\][\r\n\s\t]*?\[\/table\][\r\n\s\t]?/gi,"[/TR][/TABLE]");e=e.replace(/[\r\n\s\t]*?\[\/list\]/gi,"[/LIST]");e=e.replace(/[\r\n\s\t]*?\[\*\]?/gi,"[*]");e=e.replace(/\[p\]/gi,"<p>");e=e.replace(/\[\/p\]\n?/gi,"</p>");var p=["b","u","i",["s","del"],"table","tr","td","th"],g,m;i=p.length;for(r=0;r<i;r++){if(typeof p[r]=="object"){g=p[r][0];m=p[r][1]}else{g=m=p[r]}e=e.replace(new RegExp("\\[(\\/?)"+g+"\\]","ig"),"<$1"+m+">")}e=e.replace(/\[url\]((?:\s|\S)*?)\[\/url\]/gi,(function(e,t){return'<a href="'+s(t)+'">'+t+"</a>"}));e=e.replace(/\[url\s*=\s*((?:\s|\S)*?)\]((?:\s|\S)*?)\[\/url\]/gi,(function(e,t,r){return'<a href="'+s(t)+'">'+r+"</a>"}));e=e.replace(/\[img((?:\s|\S)*?)\]((?:\s|\S)*?)\[\/img\]/gi,(function(e,r,i){r=t.FetchImageParams(r);i=s(i);var a="";if(r.width)a+="width:"+parseInt(r.width)+"px;";if(r.height)a+="height:"+parseInt(r.height)+"px;";if(a!=="")a='style="'+a+'"';return'<img src="'+i+'"'+a+"/>"}));r=0;while(e.toLowerCase().indexOf("[color=")!=-1&&e.toLowerCase().indexOf("[/color]")!=-1&&r++<20){e=e.replace(/\[color=((?:\s|\S)*?)\]((?:\s|\S)*?)\[\/color\]/gi,((e,t,r)=>'<span style="color:'+s(t)+'">'+r+"</span>"))}r=0;while(e.toLowerCase().indexOf("[list=")!=-1&&e.toLowerCase().indexOf("[/list]")!=-1&&r++<20){e=e.replace(/\[list=1\]((?:\s|\S)*?)\[\/list\]/gi,"<ol>$1</ol>")}r=0;while(e.toLowerCase().indexOf("[list")!=-1&&e.toLowerCase().indexOf("[/list]")!=-1&&r++<20){e=e.replace(/\[list\]((?:\s|\S)*?)\[\/list\]/gi,"<ul>$1</ul>")}e=e.replace(/\[\*\]/gi,"<li>");r=0;while(e.toLowerCase().indexOf("[font=")!=-1&&e.toLowerCase().indexOf("[/font]")!=-1&&r++<20){e=e.replace(/\[font=((?:\s|\S)*?)\]((?:\s|\S)*?)\[\/font\]/gi,((e,t,r)=>'<span style="font-family:'+s(t)+'">'+r+"</span>"))}r=0;while(e.toLowerCase().indexOf("[size=")!=-1&&e.toLowerCase().indexOf("[/size]")!=-1&&r++<20){e=e.replace(/\[size=((?:\s|\S)*?)\]((?:\s|\S)*?)\[\/size\]/gi,((e,t,r)=>'<span style="font-size:'+s(t)+'">'+r+"</span>"))}if(this.parseAlign){e=e.replace(/\[(center|left|right|justify)\]/gi,(function(e,t){return'<div style="text-align:'+s(t)+'">'}));e=e.replace(/\[\/(center|left|right|justify)\]/gi,"</div>")}if(e.toLowerCase().indexOf("[/video]")!=-1){e=e.replace(/\[video((?:\s|\S)*?)\]((?:\s|\S)*?)\[\/video\]/gi,(function(e,r,i){return t.GetVideoSourse(i,t.FetchVideoParams(r.trim(r)),e)}))}e=e.replace(/\n/gi,"<br />");e=e.replace(/&#91;/gi,"[");e=e.replace(/&#93;/gi,"]");if(a.length>0){e=e.replace(/#BX_CODE(\d+)#/gi,(function(e,t){return a[t]||e}))}return e},GetNodeHtml:function(e,t){var r={node:e},i="";if(!t){if(e.nodeType==3){var s=BX.util.htmlspecialchars(e.nodeValue);if(!s.match(/[^\n]+/gi)&&e.previousSibling&&e.nextSibling&&this.editor.util.IsBlockNode(e.previousSibling)&&this.editor.util.IsBlockNode(e.nextSibling)){return"\n"}if(BX.browser.IsChrome()&&this.editor.pasteHandleMode&&e.nextSibling&&e.nextSibling.nodeName=="P"){s=s.replace(/\n+/gi,"\n")}if(e.parentNode&&!e.parentNode.getAttribute("data-bx-parent-node")&&BX.util.in_array(e.parentNode.nodeName,["P","DIV","SPAN","TD","TH","B","STRONG","I","EM","U","DEL","S","STRIKE","BLOCKQUOTE"])){s=s.replace(/\n/gi," ")}if(BX.browser.IsMac()||BX.browser.IsFirefox()){s=s.replace(/\n/gi," ")}s=s.replace(/\[/gi,"&#91;");s=s.replace(/\]/gi,"&#93;");return s}if(e.nodeType==1&&e.nodeName=="P"){var a=BX.util.trim(e.innerHTML);a=a.replace(/[\n\r\s]/gi,"").toLowerCase();if(a=="<br>"){e.innerHTML=""}}var n=this.UnParseNodeBB(r);if(n!==false){return n}if(r.bbOnlyChild)t=true;if(!t){if(r.breakLineBefore){i+="\n"}if(e.nodeType==1&&!r.hide){i+="["+r.bbTag;if(r.bbValue){i+="="+r.bbValue}i+="]"}}}if(r.checkNodeAgain){i+=this.GetNodeHtml(e)}else{var o,l,d="";for(o=0;o<e.childNodes.length;o++){l=e.childNodes[o];d+=this.GetNodeHtml(l)}i+=d}if(!t){if(r.breakLineAfter)i+="\n";if(d==""&&this.IsPairNode(r.bbTag)&&e.nodeName!=="P"&&e.nodeName!=="TD"&&e.nodeName!=="TR"&&e.nodeName!=="TH"){return""}if(e.nodeType==1&&(e.childNodes.length>0||this.IsPairNode(r.bbTag))&&!r.hide&&!r.hideRight){i+="[/"+r.bbTag+"]"}if(BX.browser.IsFirefox()&&this.editor.util.IsBlockNode(e)&&BX.util.trim(e.innerHTML.replace(/\uFEFF/gi,"")).toLowerCase()=="<br>"){return"\n"}if(r.breakLineAfterEnd||e.nodeType==1&&this.editor.util.IsBlockNode(e)&&this.editor.util.IsBlockNode(this.editor.util.GetNextSibling(e))){i+="\n"}}return i},UnParseNodeBB:function(e){var t,r,i,s=e.node.nodeName.toUpperCase();e.checkNodeAgain=false;if(s=="BR"){return"#BR#"}if(e.node&&e.node.id){t=this.editor.GetBxTag(e.node.id);if(t.tag){var a=this.editor.parser.specialParsers[t.tag];if(a&&a.UnParse){return a.UnParse(t,e,this.editor)}else if(t.tag=="video"){return t.params.value}else if(t.tag=="smile"){return t.params.code}else{return""}}}if(s=="SCRIPT"){return""}if(s=="IFRAME"&&e.node.src){var n=e.node.src.replace(/https?:\/\//gi,"//"),o=this.editor.phpParser.CheckForVideo('src="'+n+'"');if(o){var l=parseInt(e.node.width),d=parseInt(e.node.height);return"[VIDEO TYPE="+o.provider.toUpperCase()+" WIDTH="+l+" HEIGHT="+d+"]"+n+"[/VIDEO]"}}if(s=="PRE"&&BX.hasClass(e.node,"bxhtmled-code")){return"[CODE]"+this.GetCodeContent(e.node)+"[/CODE]"}if(s=="IMG"){var u="";if(e.node.style.width)u+=" WIDTH="+parseInt(e.node.style.width);else if(e.node.width)u+=" WIDTH="+parseInt(e.node.width);if(e.node.style.height)u+=" HEIGHT="+parseInt(e.node.style.height);else if(e.node.height)u+=" HEIGHT="+parseInt(e.node.height);return"[IMG"+u+"]"+e.node.src+"[/IMG]"}e.hide=false;e.bbTag=s;r=BX.util.in_array(s,this.editor.TABLE_TAGS);i=this.parseAlign&&(e.node.style.textAlign||e.node.align)&&!r;const f="var(--ui-font-family-primary, var(--ui-font-family-helvetica))";if(s=="STRONG"||s=="B"){e.bbTag="B"}else if(s=="EM"||s=="I"){e.bbTag="I"}else if(s=="DEL"||s=="S"){e.bbTag="S"}else if(s=="OL"||s=="UL"){e.bbTag="LIST";e.breakLineAfter=true;e.bbValue=s=="OL"?"1":""}else if(s=="LI"){if(e.node.lastChild&&e.node.lastChild.nodeName=="BR"){e.node.removeChild(e.node.lastChild)}e.bbTag="*";e.breakLineBefore=true;e.hideRight=true}else if(s=="A"){e.bbTag="URL";e.bbValue=this.editor.parser.GetAttributeEx(e.node,"href");if(!BX.type.isNotEmptyString(e.bbValue)){e.bbValue=""}e.bbValue=e.bbValue.replace(/\[/gi,"&#91;").replace(/\]/gi,"&#93;");if(e.bbValue===""){e.bbOnlyChild=true}}else if(e.node.style.color&&!r){e.bbTag="COLOR";e.bbValue=this.editor.util.RgbToHex(e.node.style.color);e.node.style.color="";if(e.node.style.cssText!=""){e.checkNodeAgain=true}}else if(e.node.style.fontFamily&&e.node.style.fontFamily!==f&&!r){e.bbTag="FONT";e.bbValue=e.node.style.fontFamily;e.node.style.fontFamily="";if(e.node.style.cssText!=""){e.checkNodeAgain=true}}else if(e.node.style.fontSize&&!r){e.bbTag="SIZE";e.bbValue=e.node.style.fontSize;e.node.style.fontSize="";if(e.node.style.cssText!=""){e.checkNodeAgain=true}}else if(s=="BLOCKQUOTE"&&e.node.className=="bxhtmled-quote"&&!e.node.getAttribute("data-bx-skip-check")){e.bbTag="QUOTE";e.breakLineAfterEnd=true;if(i){e.checkNodeAgain=true;e.node.setAttribute("data-bx-skip-check","Y")}}else if(i){var h=e.node.style.textAlign||e.node.align;if(BX.util.in_array(h,["left","right","center","justify"])){e.hide=false;e.bbTag=h.toUpperCase()}else{e.hide=!BX.util.in_array(s,this.editor.BBCODE_TAGS)}}else if(!BX.util.in_array(s,this.editor.BBCODE_TAGS)){e.hide=true}return false},IsPairNode:function(e){e=e.toUpperCase();return!(e.substr(0,1)=="H"||e=="BR"||e=="IMG"||e=="INPUT")},GetCodeContent:function(e){if(!e||this.editor.util.IsEmptyNode(e))return"";var t,r="";for(t=0;t<e.childNodes.length;t++){if(e.childNodes[t].nodeType==3)r+=e.childNodes[t].data;else if(e.childNodes[t].nodeType==1&&e.childNodes[t].nodeName=="BR")r+="#BR#";else r+=this.GetCodeContent(e.childNodes[t])}if(BX.browser.IsIE())r=r.replace(/\r/gi,"#BR#");else r=r.replace(/\n/gi,"#BR#");r=r.replace(/\[/gi,"&#91;");r=r.replace(/\]/gi,"&#93;");return r},GetVideoSourse:function(e,t,r,i){i=i||BX.message.BXEdVideoTitle;return this.editor.phpParser.GetVideoHTML({params:{width:t.width,height:t.height,title:i,origTitle:"",provider:t.type},html:r})},FetchVideoParams:function(e){e=BX.util.trim(e);var t=e.split(" "),r,i,s,a,n={width:180,height:100,type:false};for(r=0;r<t.length;r++){a=t[r].split("=");i=a[0].toLowerCase();s=a[1];if(i=="width"||i=="height"){s=parseInt(s,10);if(s&&!isNaN(s)){n[i]=Math.max(s,100)}}else if(i=="type"){s=s.toUpperCase();if(s=="YOUTUBE"||s=="RUTUBE"||s=="VIMEO"){n[i]=s}}}return n},FetchImageParams:function(e){e=BX.util.trim(e);var t=e.split(" "),r,i,s,a,n={};for(r=0;r<t.length;r++){a=t[r].split("=");i=a[0].toLowerCase();s=a[1];if(i=="width"||i=="height"){s=parseInt(s,10);if(s&&!isNaN(s)){n[i]=s}}}return n}};function i(e){this.editor=e;var t=["area","hr","i?frame","link","meta","noscript","style","table","tbody","thead","tfoot"],r=["li","dt","dd","h[1-6]","option","script"];this.reBefore=new RegExp("^<(/?"+t.join("|/?")+"|"+r.join("|")+")[ >]","i");this.reAfter=new RegExp("^<(br|/?"+t.join("|/?")+"|/"+r.join("|/")+")[ >]");var i=["blockquote","div","dl","fieldset","form","frameset","map","ol","p","pre","select","td","th","tr","ul"];this.reLevel=new RegExp("^</?("+i.join("|")+")[ >]");this.lastCode=null;this.lastResult=null}i.prototype={Format:function(e){if(e!=this.lastCode){this.lastCode=e;this.lastResult=this.DoFormat(e)}return this.lastResult},DoFormat:function(e){e+=" ";this.level=0;var t=this,r,i,s=0,a=null,n=null,o="",l="",d=0,u="";this.pieces={};e=e.replace(/<pre[\s\S]*?\/pre>/gi,(function(e){t.pieces[d]=e;var r="#BX_CODE_PIECE_"+d+"#";d++;return r}));for(r=0;r<e.length;r++){s=r;if(e.substr(r).indexOf("<")==-1){l+=e.substr(r);l=l.replace(/\n\s*\n/g,"\n");l=l.replace(/^[\s\n]*/,"");l=l.replace(/[\s\n]*$/,"");if(l.indexOf("\x3c!--noindex--\x3e")!==-1){l=l.replace(/(<!--noindex-->)(?:[\s|\n|\r|\t]*?)(<a[\s\S]*?\/a>)(?:[\s|\n|\r|\t]*?)(<!--\/noindex-->)(?:[\n|\r|\t]*)/gi,"$1$2$3")}l=l.replace(/#BX_CODE_PIECE_(\d+)#/g,(function(e,r){return r&&t.pieces[r]?t.pieces[r]:e}));return l}while(s<e.length&&e.charAt(s)!=="<"){s++}if(r!=s){u=e.substr(r,s-r);if(u.match(/^\s+$/)){u=u.replace(/\s+/g," ");l+=u}else{if(l.charAt(l.length-1)=="\n"){l+=this.GetTabs()}else if(u.charAt(0)=="\n"){l+="\n"+this.GetTabs();u=u.replace(/^\s+/,"")}u=u.replace(/\n/g," ");u=u.replace(/\n+/g,"");u=u.replace(/\s+/g," ");l+=u}if(u.match(/\n/)){l+="\n"+this.GetTabs()}}a=s;while(s<e.length&&e.charAt(s)!=">"){s++}o=e.substr(a,s-a);r=s;if(o.substr(1,3)==="!--"){if(!o.match(/--$/)){while(e.substr(s,3)!=="--\x3e"){s++}s+=2;o=e.substr(a,s-a);r=s}if(l.charAt(l.length-1)!=="\n"){l+="\n"}l+=this.GetTabs();l+=o+">\n"}else if(o[1]==="!"){l=this.PutTag(o+">",l)}else if(o[1]=="?"){l+=o+">\n"}else if(i=o.match(/^<(script|style)/i)){i[1]=i[1].toLowerCase();l=this.PutTag(this.CleanTag(o),l);n=String(e.substr(r+1)).toLowerCase().indexOf("</"+i[1]);if(n){u=e.substr(r+1,n);r+=n;l+=u}}else{l=this.PutTag(this.CleanTag(o),l)}}e=e.replace(/#BX_CODE_PIECE_(\d+)#/g,(function(e,r){return r&&t.pieces[r]?t.pieces[r]:e}));return e},GetTabs:function(){var e="",t;for(t=0;t<this.level;t++){e+="\t"}return e},CleanTag:function(e){var t,r=/\s*([^= ]+)(?:=((['"']).*?\3|[^ ]+))?/,i="",s="";e=e.replace(/\n/g," ");e=e.replace(/[\s]{2,}/g," ");e=e.replace(/^\s+|\s+$/g," ");if(e.match(/\/$/)){s="/";e=e.replace(/\/+$/,"")}while(t=r.exec(e)){if(t[2])i+=t[1]+"="+t[2];else if(t[1])i+=t[1];i+=" ";e=e.substr(t[0].length)}return i.replace(/\s*$/,"")+s+">"},PutTag:function(e,t){var r=e.match(this.reLevel);if(e.match(this.reBefore)||r){t=t.replace(/\s*$/,"");t+="\n"}if(r&&e.charAt(1)=="/"){this.level--}if(t.charAt(t.length-1)=="\n"){t+=this.GetTabs()}if(r&&"/"!=e.charAt(1)){this.level++}t+=e;if(e.match(this.reAfter)||e.match(this.reLevel)){t=t.replace(/ *$/,"");t+="\n"}return t}};function s(){window.BXHtmlEditor.BXCodeFormatter=i;window.BXHtmlEditor.BXEditorParser=e;window.BXHtmlEditor.BXEditorPhpParser=t;window.BXHtmlEditor.BXEditorBbCodeParser=r}if(window.BXHtmlEditor){s()}else{BX.addCustomEvent(window,"OnBXHtmlEditorInit",s)}})();
//# sourceMappingURL=html-parser.map.js